// pages/chatroom/chatroom.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        language: '法语',   //当前选择的语言
        translate2lan: ['法语', '西班牙语', '德语', '法语', '意大利语', '法语', '法语', '法语',],   // 选择的翻译语言
        users: [{
            name: '张三',
            avatar: 'http://5b0988e595225.cdn.sohucs.com/images/20170928/298ae5347f0d4d51af2f7fef537ebaa2.jpeg',
        }, {
            name: '张三',
            avatar: 'http://5b0988e595225.cdn.sohucs.com/images/20170928/298ae5347f0d4d51af2f7fef537ebaa2.jpeg',
        },],    //进入房间的用户信息   
        inputValue: '',     // 输入框值
        chatData: [{
            user: {
                name: '张三',
                avatarUrl: 'http://5b0988e595225.cdn.sohucs.com/images/20170928/298ae5347f0d4d51af2f7fef537ebaa2.jpeg',
                userAccountId: '1'
            },
            content: '你好啊',
            type: 'chat',
        }, {
            inviter: '张三',
            type: 'info',
        }, {
            user: {
                name: '张三',
                avatarUrl: 'http://5b0988e595225.cdn.sohucs.com/images/20170928/298ae5347f0d4d51af2f7fef537ebaa2.jpeg',
                userAccountId: '2'
            },
            content: '你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊',
            type: 'chat',
        },],    // 对话信息
        userAccountId: '1', //当前用户
        allLanguage: [],      // 所有语言
        showCurLayer: false,    // 当前语言的遮罩层
        showTransLayer: false,    // 翻译语言的遮罩层
        chooseItemIndex: 0, // 自己当前的语言
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var language = getApp().globalData.languages;
        language = language.map((item) => {
            item.checked = false;
            return item;
        })
        this.setData({
            allLanguage: language,
        });
    },

    // -------------------layer begin----------------------
    chooseDefaultLanguage: function () {
        this.setData({
            showCurLayer: true,
        })
    },

    hideLayer: function () {
        this.setData({
            showCurLayer: false,    // 当前语言的遮罩层
            showTransLayer: false,    // 翻译语言的遮罩层
        });
    },

    chooseItem: function (e) {
        var index = e.currentTarget.dataset.index;
        this.setData({
            chooseItemIndex: index,
        });
    },

    chooseTransItem: function (e) {
        var index = e.currentTarget.dataset.index;
        var allLanguage = this.data.allLanguage;

        this.setData({
            [`allLanguage[` + index + `].checked`]: allLanguage[index].checked ? false : true,
        });
    },

    chooseTranslateLanguage: function () {
        this.setData({
            showTransLayer: true,
        });
    },
    // ----------------------layer end----------------------

    gotoUserList: function () {
        wx.navigateTo({
            url: '/pages/chatroom/userList/userList',
        });
    },

    togoMySetting: function () {
        wx.navigateTo({
            url: '/pages/my/my',
        });
    },

    inputChange: function (e) {
        var value = e.detail.value;

        this.setData({
            inputValue: value
        });
    },

})